﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using SMG.Presentation.Generics;

namespace SMG.Presentation
{
    /// <summary>
    /// Interaction logic for WGrupoConsulta.xaml
    /// </summary>
    public partial class WGrupoConsulta : Window
    {
        public WGrupoConsulta()
        {
            InitializeComponent();
        }

        public Grupo retorno;

        private void btnConsultar_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                List<Grupo> lista;
                string nome = this.txtNome.Text;

                using (Data bd = new Data(Util.getConnectionString()))
                {
                    lista = (from s in bd.Grupos
                                where (String.IsNullOrEmpty(nome) || s.Nome.Contains(nome))
                                select s).ToList();
                }

                lstResult.ItemsSource = lista;
                
                if (lista.Count.Equals(0))
                {
                    MessageBox.Show("Nenhum Grupo encontrado");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void lstResult_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (this.lstResult.SelectedItem != null)
                {
                    retorno = (Grupo)this.lstResult.SelectedItem;
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
